package lol.niconico.libtest.di

import android.app.Application
import androidx.room.Room
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ApplicationComponent
import lol.niconico.libtest.TestData
import lol.niconico.libtest.data.db.AppDatabase
import lol.niconico.libtest.http.GithubService
import javax.inject.Singleton

/**
 * Created by ZhangQianqian on 2020/7/8  16:36.
 * email 415692689@qq.com
 */
@Module
@InstallIn(ApplicationComponent::class)
object AppModule {

    @Provides
    @Singleton
    fun provideAnalyticsService(): TestData {
        return TestData("provideAnalyticsService")
    }

    @Provides
    @Singleton
    fun provideGithubService(): GithubService {
        return GithubService.create()
    }

    @Provides
    @Singleton
    fun provideDb(application: Application): AppDatabase {
        return Room
            .databaseBuilder(application, AppDatabase::class.java, "test.db")
            .fallbackToDestructiveMigration()
            .allowMainThreadQueries()
            .build()
    }
}